package com.chaihu.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chaihu.bean.dto.user.UserDto;
import com.chaihu.bean.in.user.userinfo.QueryUserIn;
import com.chaihu.bean.out.user.userinfo.QueryUserOut;
import com.chaihu.bean.result.ResponseResult;
import com.chaihu.intf.icommon.BaseService;
import com.chaihu.intf.user.QueryUsersService;
import com.chaihu.user.dao.UserDao;
import com.chaihu.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class QueryUsersServiceImpl extends BaseService<ResponseResult<List<QueryUserOut>>, QueryUserIn> implements QueryUsersService {
    @Autowired
    private UserDao userDao;

    @Override
    public ResponseResult<List<QueryUserOut>> checkHandle(ResponseResult<List<QueryUserOut>> responseResult, QueryUserIn in) {
        return responseResult;
    }

    @Override
    public ResponseResult<List<QueryUserOut>> doHandle(ResponseResult<List<QueryUserOut>> responseResult, QueryUserIn in) {
        LambdaQueryWrapper<UserDto> queryWrapper = Wrappers.lambdaQuery(in);
        List<UserDto> users = userDao.selectList(queryWrapper);

        List<QueryUserOut> queryUserOuts = BeanConvertUtil.covertBeanList(users, QueryUserOut.class);
        responseResult.setData(queryUserOuts);
        return responseResult;
    }

    @Override
    public ResponseResult<List<QueryUserOut>> respHandle(ResponseResult<List<QueryUserOut>> responseResult, QueryUserIn in) {
        return responseResult;
    }

    @Override
    public ResponseResult<List<QueryUserOut>> queryUsers(QueryUserIn in) {
        ResponseResult<List<QueryUserOut>> result = new ResponseResult<>();
        return this.mainHandle(result,in);
    }
}
